//! Error handling for R-XShell

use thiserror::Error;
use std::io;

/// Result type alias for R-XShell operations
pub type Result<T> = std::result::Result<T, ShellError>;

/// Main error type for R-XShell operations
#[derive(Error, Debug)]
pub enum ShellError {
    #[error("IO error: {0}")]
    Io(#[from] io::Error),
    
    #[error("Command execution failed: {0}")]
    CommandFailed(String),
    
    #[error("Invalid command: {0}")]
    InvalidCommand(String),
    
    #[error("Configuration error: {0}")]
    Config(String),
    
    #[error("Parse error: {0}")]
    Parse(String),
    
    #[error("Environment error: {0}")]
    Environment(String),
    
    #[error("Permission denied: {0}")]
    PermissionDenied(String),
    
    #[error("Timeout: operation took too long")]
    Timeout,
    
    #[error("Unknown error: {0}")]
    Unknown(String),
}

impl ShellError {
    /// Create a new command failed error
    pub fn command_failed<S: Into<String>>(msg: S) -> Self {
        ShellError::CommandFailed(msg.into())
    }
    
    /// Create a new invalid command error
    pub fn invalid_command<S: Into<String>>(msg: S) -> Self {
        ShellError::InvalidCommand(msg.into())
    }
    
    /// Create a new configuration error
    pub fn config<S: Into<String>>(msg: S) -> Self {
        ShellError::Config(msg.into())
    }
    
    /// Create a new parse error
    pub fn parse<S: Into<String>>(msg: S) -> Self {
        ShellError::Parse(msg.into())
    }
}